﻿namespace _2.策略模式;

public class CashContext
{
    CashSuper? cs = null;

    /// <summary>
    /// 根据所选字符串创建对应折扣方案对象
    /// </summary>
    /// <param name="type">折扣方案</param>
    public CashContext(string? type)
    {
        switch (type)
        {
            case "正常收费":
                cs = new CashNormal();
                break;
            case "满300返100":
                cs = new CashReturn("300", "100");
                break;
            case "打8折":
                cs = new CashRebate("0.8");
                break;
        }

    }

    /// <summary>
    /// 调用收费方案算法，获取应收现金
    /// </summary>
    /// <param name="money">原价</param>
    /// <returns>现价</returns>
    /// <exception cref="没有这种收费方案"></exception>
    public double GetResult(double money)
    {
        if (cs != null)
            return cs.AcceptCash(money);
        else
            throw new Exception("没有这种收费方案");
    }
}
